package com.puff.controller.rider;

import com.puff.constant.JwtClaimsConstant;
import com.puff.constant.RoleConstant;
import com.puff.dto.EmployeeLoginDTO;
import com.puff.dto.RiderLoginDTO;
import com.puff.dto.RiderRegisterDTO;
import com.puff.entity.Employee;
import com.puff.entity.Rider;
import com.puff.result.Result;
import com.puff.service.RiderService;
import com.puff.utils.JwtUtil;
import com.puff.vo.EmployeeLoginVO;
import com.puff.vo.RiderLoginVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/rider/rider")
@Slf4j
@Api(tags = "骑手相关接口") //swagger注解信息
public class RiderController {

    @Autowired
    private RiderService riderService;

    /**
     * 骑手注册
     * @param riderRegisterDTO
     * @return
     */
    @PostMapping("/register")
    @ApiOperation(value = "骑手注册")
    public Result register(@RequestBody RiderRegisterDTO riderRegisterDTO) {
        log.info("骑手注册：{}", riderRegisterDTO);

        riderService.register(riderRegisterDTO);

        return Result.success();
    }

    /**
     * 骑手登录
     * @param riderLoginDTO
     * @return
     */
    @PostMapping("/login")
    @ApiOperation(value = "骑手登录")
    public Result<RiderLoginVO> login(@RequestBody RiderLoginDTO riderLoginDTO) {
        log.info("骑手登录：{}", riderLoginDTO);

        Rider rider = riderService.login(riderLoginDTO);

        RiderLoginVO riderLoginVO = RiderLoginVO.builder()
                .id(rider.getId())
                .username(rider.getUsername())
                .name(rider.getName())
                .build();

        return Result.success(riderLoginVO);
    }
}
